#pragma semicolon 1
//#pragma newdecls required
#include <sourcemod>
#include <sdktools>

#define PLUGIN_NAME                   "l4d2_Witch_attacker_jump"    //这里写插件名字
#define PLUGIN_AUTHOR                 "豆瓣酱な"                         //作者
#define PLUGIN_DESCRIPTION            "Witch 普通攻击击飞玩家"   //介绍
#define PLUGIN_VERSION                "1.0"
#define PLUGIN_URL                    "https://gitee.com/sweet-and-sour-bombs"  //网站

new g_iVelocity	= -1;


public Plugin myinfo =
{
    name        = PLUGIN_NAME,
    author      = PLUGIN_AUTHOR,
    description = PLUGIN_DESCRIPTION,
    version     = PLUGIN_VERSION,
    url         = PLUGIN_URL
}



public void OnPluginStart()
{
	if((g_iVelocity = FindSendPropInfo("CBasePlayer", "m_vecVelocity[0]")) == -1)
	LogError("Could not find offset for CBasePlayer::m_vecVelocity[0]");

	HookEvent("player_hurt", Event_PlayerHurt, EventHookMode_Pre); //玩家受伤
	HookEvent("player_incapacitated",			Event_PlayerIncapacitated, EventHookMode_Pre);  //玩家倒地事件
}



/* 玩家受伤 */
public Action:Event_PlayerHurt(Handle:event, String:event_name[], bool:dontBroadcast)
{
	new victim = GetClientOfUserId(GetEventInt(event, "userid"));
	new attackerentid = GetEventInt(event, "attackerentid");
	decl String:classname[20];
	if(IsValidEdict(attackerentid))
	{
		GetEdictClassname(attackerentid, classname, 20);
		if(StrEqual(classname, "witch", false))
		{
			
			AddVelocity(victim, 200.0, 500.0); //这里改击飞高度.第一个参数200.0表示水平速度为200，第二个参数500.0表示垂直速度为500
			
		}
	}
	return Plugin_Handled;
}	

/* 玩家倒地 */
public Action:Event_PlayerIncapacitated(Handle:event, String:event_name[], bool:dontBroadcast)
{
	new victim = GetClientOfUserId(GetEventInt(event, "userid"));
	new attackerentid = GetEventInt(event, "attackerentid");
	decl String:classname[20];
	if(IsValidEdict(attackerentid))
	{
		GetEdictClassname(attackerentid, classname, 20);
		if(StrEqual(classname, "witch", false))
		{
			
			AddVelocity(victim, 200.0, 500.0); //这里改击飞高度.第一个参数200.0表示水平速度为200，第二个参数500.0表示垂直速度为500
			
		}
	}
	return Plugin_Handled;
}	



public AddVelocity(client, Float:xSpeed, Float:zSpeed)
{
	if(g_iVelocity == -1) return;
	
	new Float:vecVelocity[3];
	GetEntDataVector(client, g_iVelocity, vecVelocity);
	
	if(GetRandomInt(0, 1))
	{
		vecVelocity[0] -= xSpeed;
	}
	else
	{
		vecVelocity[0] += xSpeed;
	}
	
	if(GetRandomInt(0, 1))
	{
		vecVelocity[1] -= xSpeed;
	}
	else
	{
		vecVelocity[1] += xSpeed;
	}
	vecVelocity[2] += zSpeed;
	
	TeleportEntity(client, NULL_VECTOR, NULL_VECTOR, vecVelocity);

}





















